
package com.guocheng.utils;

import org.apache.shiro.crypto.hash.Md5Hash;

public class PasswordUtils {

    private static String salt = "guochengFace";

    public static String getMD5Password(String password){
        return new Md5Hash(password,salt,2).toString();
    }

    /**
     * 密码比较
     * @param s1 数据库中的密码
     * @param password 用户输入的密码
     * @return
     */
    public static boolean passwordEquals(String s1,char[] password){
        return new Md5Hash(password, salt, 2).toString().equals(s1);
    }

    public static void main(String[] args) {
        String password = "123456";
        String password1 = getMD5Password(password);
        System.out.println("密码: "+password1);
        System.out.println("盐: "+salt);

        boolean b = passwordEquals("221ee6885eb87fbd12c303ece5b72663", "123456".toCharArray());
        System.out.println(b);
    }
}
